package com.example.managemyself.data.repository;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.example.managemyself.ManageMyself;

/**
 * 仓库工厂类，根据配置创建本地或远程仓库
 */
public class RepositoryFactory {
    
    private static final String PREF_NAME = "repository_settings";
    private static final String KEY_USE_REMOTE = "use_remote_repository";
    
    /**
     * 获取任务仓库实例
     */
    public static ITaskRepository getTaskRepository(Application application) {
        if (isUsingRemoteRepository(application)) {
            return new MySQLTaskRepository();
        } else {
            return new TaskRepository(application);
        }
    }
    
    /**
     * 检查是否使用远程仓库
     */
    public static boolean isUsingRemoteRepository(Context context) {
        SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        return prefs.getBoolean(KEY_USE_REMOTE, false);
    }
    
    /**
     * 设置是否使用远程仓库
     */
    public static void setUseRemoteRepository(Context context, boolean useRemote) {
        SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        prefs.edit().putBoolean(KEY_USE_REMOTE, useRemote).apply();
    }
} 